//
//  MyMessageModel.swift
//  Venus
//
//  Created by qurongxiang on 2018/9/4.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit
import SwiftyJSON


class MyMessageModel: NSObject {
    /// 消息ID
    var id : Int = 0
    
    /// 来自用户模型
    var fromUser:FromUserModel = FromUserModel()
    
    /// 消息内容
    var msg:String = ""
    
    ///被回复的内容
    var replyMsg:String = ""
    
    ///消息类型 0:回复消息1:回复话题2:管理员删除话题3:被删话题作者申诉4:点赞
    var msgType:Int = 999
    
    var msgId : Int = 0
    
    /// 时间
    var createTime:String = ""
    
    var cellHeight:CGFloat = 0
    
    override init() {
        
    }
    
    
    /// 格式化数据
    ///
    /// - Parameter json:
    /// - Returns: 
    class func formatModel(json:JSON!) -> [MyMessageModel] {
        var modelArr:[MyMessageModel] = [MyMessageModel]()
        if json.isEmpty{ return modelArr }
        let arr =  json["data"].arrayValue
        
        for resourceJson in arr{
            let model = MyMessageModel()
            model.id = resourceJson["id"].intValue
            model.msg = resourceJson["msg"].stringValue
            model.createTime = resourceJson["createTime"].stringValue
            model.replyMsg = resourceJson["replyMsg"].stringValue
            let userJson = resourceJson["fromUser"]
            if !userJson.isEmpty{
                model.fromUser = FromUserModel(fromJson: userJson)
            }
            modelArr.append(model)
        }
        return modelArr
    }
    
    
}

class FromUserModel:NSObject {
    
    /// 用户姓名
    var userName:String = ""
    
    /// 用户头像
    var headImg:String = ""
    
    override init() {
        
    }
    
    init(fromJson json: JSON!){
        if json.isEmpty{ return }
        userName = json["userName"].stringValue
        headImg = json["headImg"].stringValue
    }
}
